package com.thy.utils;

import com.hospital.common.dto.message.module.AddMessageDto;
import com.thy.feign.MessageFeign;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class MessageUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }
    public static void sendMessage(Long senderId,Long receiverId,String messageContent){
        AddMessageDto addMessageDto = new AddMessageDto();
        addMessageDto.setSenderId(senderId);
        addMessageDto.setReceiverId(receiverId);
        addMessageDto.setMessageContent(messageContent);
        addMessageDto.setMessageType(1);
        // 通过ApplicationContext获取Feign客户端
        MessageFeign messageFeign = applicationContext.getBean(MessageFeign.class);
        messageFeign.addMessage(addMessageDto);
    }
}
